<template>
  <div class="app-container">
    </el-form>

      <!-- 表格 -->
      <el-table
        :data="list"
        border
        fit
        highlight-current-row
        row-class-name="myClassList">


        <el-table-column
          label="序号"
          width="70"
          align="center">
          <template slot-scope="scope">
            {{ (page - 1) * limit + scope.$index + 1 }}
          </template>
        </el-table-column>

         <el-table-column prop="username" label="用户名" />
         <el-table-column prop="email" label="邮箱" />
         <el-table-column prop="phone" label="手机号" />
         <el-table-column prop="age" label="年龄" />
        <el-table-column label="性别" align="center">
          <template slot-scope="scope">
            {{ scope.row.sex === 1? '男' : '女' }}
          </template>
        </el-table-column>
         <el-table-column label="角色" width="150" align="center">
           <template slot-scope="scope">
             <router-link :to="'/admin/save/'+scope.row.id">
             <el-button type="primary" size="mini">为其分配角色</el-button>
             </router-link>
           </template>
         </el-table-column>


           <el-table-column label="操作" width="150" align="center">
             <template slot-scope="scope">
               <el-button type="success" size="mini" @click="adminAdopt(scope.row.id)">通过</el-button>
               <el-button type="danger" size="mini"  @click="adminFail(scope.row.id)">失败</el-button>
             </template>
           </el-table-column>
         </el-table>



  </div>
</template>

<script>
  //引入banner.js文件
  import admin from'@/api/banner/banner'
  export default {
    //写核心代码
   data() {//定义当前页面变量及设定初始值
     return {
       page:1,//当前页
       limit:10,//每页的记录数
       list:[],//查询之后接口返回的集合
     }
    },

    created(){//页面渲染之前执行，一般都是调用methods里面的方法
      this.getAdmins()
    },


    methods:{
    getAdmins(){//默认page为1
      admin.getAdmins(0)
      .then(response=>{//请求成功
        //为变量赋值
        this.list=response.data.list
      })
      .catch(error=>{//请求失败
      this.$message({
        type: 'error',
        message: response.message
       })
      })
    },
    //管理员审核通过
    adminAdopt(adminId){
      admin.adminAdopt(adminId)
      .then(response=>{
        this.$message({
          type: 'success',
          message:'审核完成'
         })
         this.getAdmins()
      })
    },
    //管理员审核失败
    adminFail(adminId){
      admin.adminFail(adminId)
      .then(response=>{
        this.$message({
          type: 'success',
          message:'审核完成'
         })
      })
      this.getAdmins()
    }
   }
  }
</script>

<style>
</style>
